## innovus 18.15 & 20.17

set path /projects/cascade/workspace/xwqiu/RDL/innovus.20251106

source ${path}/RDL_Routing/proc_RDL.tcl
set wire(AP,width,in) 28
set wire(AP,width,out) 22

proc pr_draw_AP_right {} {
	global wire
	set bumps [dbget selected]

	foreach bump ${bumps} {
		set bump_name [dbget $bump.net.name]
		set bump_box_llx [dbget $bump.bump_shape_bbox_llx]
		set bump_box_lly [dbget $bump.bump_shape_bbox_lly]
		set bump_box_urx [dbget $bump.bump_shape_bbox_urx]
		set bump_box_ury [dbget $bump.bump_shape_bbox_ury]
		set bump_box_centerx [dbget $bump.bump_shape_center_x]
		set bump_box_centery [dbget $bump.bump_shape_center_y]

		## top
		set top_start_x [expr ${bump_box_centerx}-$wire(AP,width,in)/2]
		set top_end_x   [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set top_y       [expr ${bump_box_ury}+3+$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${top_start_x} ${top_y}"
		set pt_end "${top_end_x} ${top_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
		
		## bottom
		set bottom_start_x [expr ${bump_box_centerx}-$wire(AP,width,in)/2]
		set bottom_end_x   [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set bottom_y       [expr ${bump_box_lly}-3-$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${bottom_start_x} ${bottom_y}"
		set pt_end "${bottom_end_x} ${bottom_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## right
		set right_x [expr ${bump_box_urx}+3+$wire(AP,width,out)/2]
		set right_start_y   [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set right_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${right_x} ${right_start_y}"
		set pt_end "${right_x} ${right_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## in
		set in_x ${bump_box_centerx}
		set in_start_y   [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set in_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${in_x} ${in_start_y}"
		set pt_end "${in_x} ${in_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,in) $pt_list

		set bottom_start_x [expr ${bump_box_centerx}-$wire(AP,width,in)/2]
		set bottom_end_x   [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set bottom_y       ${bump_box_centery}
		set pt_list {}
		set pt_start "${bottom_start_x} ${bottom_y}"
		set pt_end "${bottom_end_x} ${bottom_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

	}
}

proc pr_draw_AP_left {} {
	global wire
	set bumps [dbget selected]

	foreach bump ${bumps} {
		set bump_name [dbget $bump.net.name]
		set bump_box_llx [dbget $bump.bump_shape_bbox_llx]
		set bump_box_lly [dbget $bump.bump_shape_bbox_lly]
		set bump_box_urx [dbget $bump.bump_shape_bbox_urx]
		set bump_box_ury [dbget $bump.bump_shape_bbox_ury]
		set bump_box_centerx [dbget $bump.bump_shape_center_x]
		set bump_box_centery [dbget $bump.bump_shape_center_y]

		## top
		set top_end_x [expr ${bump_box_centerx}+$wire(AP,width,in)/2]
		set top_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set top_y       [expr ${bump_box_ury}+3+$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${top_start_x} ${top_y}"
		set pt_end "${top_end_x} ${top_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
		
		## bottom
		set bottom_end_x [expr ${bump_box_centerx}+$wire(AP,width,in)/2]
		set bottom_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set bottom_y       [expr ${bump_box_lly}-3-$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${bottom_start_x} ${bottom_y}"
		set pt_end "${bottom_end_x} ${bottom_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## left
		set left_x [expr ${bump_box_llx}-3-$wire(AP,width,out)/2]
		set left_start_y   [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set left_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${left_x} ${left_start_y}"
		set pt_end "${left_x} ${left_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## in
		set in_x ${bump_box_centerx}
		set in_start_y   [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set in_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${in_x} ${in_start_y}"
		set pt_end "${in_x} ${in_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,in) $pt_list

		set bottom_end_x [expr ${bump_box_centerx}+$wire(AP,width,in)/2]
		set bottom_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set bottom_y       ${bump_box_centery}
		set pt_list {}
		set pt_start "${bottom_start_x} ${bottom_y}"
		set pt_end "${bottom_end_x} ${bottom_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
	}
}

proc pr_draw_AP_top {} {
	global wire
	set bumps [dbget selected]

	foreach bump ${bumps} {
		set bump_name [dbget $bump.net.name]
		set bump_box_llx [dbget $bump.bump_shape_bbox_llx]
		set bump_box_lly [dbget $bump.bump_shape_bbox_lly]
		set bump_box_urx [dbget $bump.bump_shape_bbox_urx]
		set bump_box_ury [dbget $bump.bump_shape_bbox_ury]
		set bump_box_centerx [dbget $bump.bump_shape_center_x]
		set bump_box_centery [dbget $bump.bump_shape_center_y]

		## top
		set top_end_x [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set top_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set top_y       [expr ${bump_box_ury}+3+$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${top_start_x} ${top_y}"
		set pt_end "${top_end_x} ${top_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
		
		## left
		set left_x [expr ${bump_box_llx}-3-$wire(AP,width,out)/2]
		set left_start_y   [expr ${bump_box_centery}-$wire(AP,width,in)/2]
		set left_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${left_x} ${left_start_y}"
		set pt_end "${left_x} ${left_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## right
		set right_x [expr ${bump_box_urx}+3+$wire(AP,width,out)/2]
		set right_start_y   [expr ${bump_box_centery}-$wire(AP,width,in)/2]
		set right_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${right_x} ${right_start_y}"
		set pt_end "${right_x} ${right_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## in
		set in_y ${bump_box_centery}
		set in_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set in_end_x     [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${in_start_x} ${in_y}"
		set pt_end "${in_end_x} ${in_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,in) $pt_list

		set right_x ${bump_box_centerx}
		set right_start_y   [expr ${bump_box_centery}-$wire(AP,width,in)/2]
		set right_end_y     [expr ${bump_box_ury}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${right_x} ${right_start_y}"
		set pt_end "${right_x} ${right_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
	}
}

proc pr_draw_AP_bottom {} {
	global wire
	set bumps [dbget selected]

	foreach bump ${bumps} {
		set bump_name [dbget $bump.net.name]
		set bump_box_llx [dbget $bump.bump_shape_bbox_llx]
		set bump_box_lly [dbget $bump.bump_shape_bbox_lly]
		set bump_box_urx [dbget $bump.bump_shape_bbox_urx]
		set bump_box_ury [dbget $bump.bump_shape_bbox_ury]
		set bump_box_centerx [dbget $bump.bump_shape_center_x]
		set bump_box_centery [dbget $bump.bump_shape_center_y]

		## bottom
		set bottom_end_x [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set bottom_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set bottom_y       [expr ${bump_box_lly}-3-$wire(AP,width,out)/2]
		set pt_list {}
		set pt_start "${bottom_start_x} ${bottom_y}"
		set pt_end "${bottom_end_x} ${bottom_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## left
		set left_x [expr ${bump_box_llx}-3-$wire(AP,width,out)/2]
		set left_end_y   [expr ${bump_box_centery}+$wire(AP,width,in)/2]
		set left_start_y     [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${left_x} ${left_start_y}"
		set pt_end "${left_x} ${left_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## right
		set left_x [expr ${bump_box_urx}+3+$wire(AP,width,out)/2]
		set left_end_y   [expr ${bump_box_centery}+$wire(AP,width,in)/2]
		set left_start_y     [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${left_x} ${left_start_y}"
		set pt_end "${left_x} ${left_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list

		## in
		set in_y ${bump_box_centery}
		set in_start_x   [expr ${bump_box_llx}-3-$wire(AP,width,out)]
		set in_end_x     [expr ${bump_box_urx}+3+$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${in_start_x} ${in_y}"
		set pt_end "${in_end_x} ${in_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,in) $pt_list

		set left_x ${bump_box_centerx}
		set left_end_y   [expr ${bump_box_centery}+$wire(AP,width,in)/2]
		set left_start_y     [expr ${bump_box_lly}-3-$wire(AP,width,out)]
		set pt_list {}
		set pt_start "${left_x} ${left_start_y}"
		set pt_end "${left_x} ${left_end_y}"

		lappend pt_list $pt_start $pt_end
		puts $pt_list

		pr_auto_edit_wire AP $bump_name $wire(AP,width,out) $pt_list
	}
}